package com.geiv.backend.controller;

import com.geiv.backend.request.AddRequest;
import com.geiv.backend.request.AddStudent;
import com.geiv.backend.request.AddStudentRequest;
import com.geiv.backend.request.SelectStudentRequest;
import com.geiv.backend.result.Teacher_GradeList;
import com.geiv.backend.result.Teacher_NoSelectedStudent;
import com.geiv.backend.result.Teacher_StudentList;
import com.geiv.backend.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * FileName:TeacherController
 * Author:  shadowsouls
 * Date:    2021/6/13 15:51
 * Description: 教师端的对外接口
 */
@RestController
@RequestMapping("teacher")
@CrossOrigin
public class TeacherController {
    @Autowired
    TeacherService service;

    //获取学生列表
    @GetMapping("getStudentList/{tid}")
    Teacher_StudentList getStudentList(@PathVariable String tid) {
        return service.getTeacher_StudentListByTeacherId(tid);
    }

    //根据对应的学号来获取成绩列表
    @GetMapping("getGradeList/{tid}/{sid}")
    Teacher_GradeList getGradeList(@PathVariable String sid, @PathVariable String tid) {
        return service.getTeacher_GradeListBySIdAndTId(sid, tid);
    }

    //添加成绩
    @PostMapping("addGrade")
    AddRequest addGrade(@RequestBody AddRequest addRequest) {
        service.addGrade(addRequest);
        System.out.println(addRequest);
        return addRequest;
    }

    // 删除成绩
    @DeleteMapping("deleteGrade/{gid}")
    String deleteGrade(@PathVariable String gid) {
        System.out.println("要删除的是" + gid);
        service.deleteGrade(gid);
        return gid;
    }

    //删除学生
    @DeleteMapping("deleteStudent/{TWSid}")
    String deleteStudent(@PathVariable String TWSid) {
        System.out.println("要删除的是" + TWSid);
        service.deleteStudent(TWSid);
        return TWSid;
    }
    //todo 增加学生 对student表与user表进行操作

    @PostMapping("addStudent")
    AddStudentRequest addStudent(@RequestBody AddStudentRequest request) {
        request.getStudentList().forEach(item -> {
            service.addStudent(item);
            System.out.println("添加学生"+item.getName());
        });
        return request;
    }

    //todo 获取不在自己管理下的学生 对student表与TWS表进行查询

    @GetMapping("getNoSelectStudent/{tid}")
    List<Teacher_NoSelectedStudent> getNoSelectStudent(@PathVariable String tid) {
        return service.getNoSelectedStudent(tid);
    }

    //todo 将学生移动到自己管理下 对TWS表进行添加
    @PostMapping("selectStudentToManger")
    SelectStudentRequest selectStudent(@RequestBody SelectStudentRequest request) {
        service.insertStudentToTWS(request.getTeacherId(), request.getSidList());
        return request;
    }

    @GetMapping("login/{username}/{password}")
    String login(@PathVariable String username, @PathVariable String password){
        return service.teacherLogin(username,password);
    }
}
